//
//  StatusToolBar.m
//  weibo
//
//  Created by qiuming on 15/12/27.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "StatusToolBar.h"

@implementation StatusToolBar {
    /// 转发微博
    UIButton *_retweetedButton;
    /// 评论按钮
    UIButton *_commentButton;
    /// 点赞按钮
    UIButton *_likeButton;
}

- (void)setViewModel:(StatusViewModel *)statusModel {
    
    _viewModel = statusModel;
    
    [_retweetedButton setTitle:statusModel.repostsCountStr forState:UIControlStateNormal];
    [_commentButton setTitle:statusModel.commentsCountStr forState:UIControlStateNormal];
    [_likeButton setTitle:statusModel.attitudesCountStr forState:UIControlStateNormal];
}


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    // 创建控件
    _retweetedButton = [UIButton buttonWithTitle:@" 转发" color:[UIColor darkGrayColor] fontSize:12 imageName:@"timeline_icon_retweet" backImageName:@"timeline_card_middle_background"];
    
    _commentButton = [UIButton buttonWithTitle:@" 评论" color:[UIColor darkGrayColor] fontSize:12 imageName:@"timeline_icon_comment" backImageName:@"timeline_card_middle_background"];
    
    _likeButton = [UIButton buttonWithTitle:@" 点赞" color:[UIColor darkGrayColor] fontSize:12 imageName:@"timeline_icon_unlike" backImageName:@"timeline_card_middle_background"];
    
    // 工具条中的分隔线
    UIImageView *sep1 = [UIImageView imageViewWithImageName:@"timeline_card_bottom_line_highlighted"];
    UIImageView *sep2 = [UIImageView imageViewWithImageName:@"timeline_card_bottom_line_highlighted"];
    
    // 添加控件
    [self addSubview:_retweetedButton];
    [self addSubview:_commentButton];
    [self addSubview:_likeButton];
    [self addSubview:sep1];
    [self addSubview:sep2];
    
    // 自动布局
    [_retweetedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.mas_bottom);
    }];
    [_commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_retweetedButton.mas_top);
        make.left.equalTo(_retweetedButton.mas_right);
        make.bottom.equalTo(_retweetedButton.mas_bottom);
        make.width.equalTo(_retweetedButton.mas_width);
    }];
    [_likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_commentButton.mas_top);
        make.left.equalTo(_commentButton.mas_right);
        make.bottom.equalTo(_commentButton.mas_bottom);
        make.width.equalTo(_commentButton.mas_width);
        
        make.right.equalTo(self.mas_right);
    }];
    [sep1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_retweetedButton.mas_right);
        make.centerY.equalTo(self.mas_centerY);
        make.width.mas_equalTo(1);
        make.height.equalTo(_retweetedButton.mas_height).multipliedBy(0.6);
    }];
    [sep2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_commentButton.mas_right);
        make.centerY.equalTo(self.mas_centerY);
        make.width.mas_equalTo(1);
        make.height.equalTo(_commentButton.mas_height).multipliedBy(0.6);
        
    }];
}


@end
